﻿using System;
using System.IO;

namespace WebApi.Helpers
{
    public class FileHelper
    {
        /// <summary>
        /// base64转图片并存本地
        /// </summary>
        public static string SaveImageFromBase64(string base64Str, string path, string imgName)
        {
            string img_path = "";
            try
            {
                if (string.IsNullOrEmpty(base64Str))
                    return "";
                byte[] b = Convert.FromBase64String(base64Str);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                img_path = Path.Combine(path, imgName);//
                System.IO.File.WriteAllBytes(img_path, b);
            }
            catch (Exception ex) {
                img_path = "";
            }
            return img_path;
        }
    }
}
